package com.sjgs.gis.service;

import com.sjgs.gis.domain.JdbcCluster;
import com.sjgs.gis.repository.JdbcClusterRepository;
import com.sjgs.gis.service.dto.JdbcClusterDTO;
import com.sjgs.gis.service.mapper.JdbcClusterMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link JdbcCluster}.
 */
@Service
@Transactional
public class JdbcClusterService {

    private final Logger log = LoggerFactory.getLogger(JdbcClusterService.class);

    private final JdbcClusterRepository jdbcClusterRepository;

    private final JdbcClusterMapper jdbcClusterMapper;

    public JdbcClusterService(JdbcClusterRepository jdbcClusterRepository, JdbcClusterMapper jdbcClusterMapper) {
        this.jdbcClusterRepository = jdbcClusterRepository;
        this.jdbcClusterMapper = jdbcClusterMapper;
    }

    /**
     * Save a jdbcCluster.
     *
     * @param jdbcClusterDTO the entity to save.
     * @return the persisted entity.
     */
    public JdbcClusterDTO save(JdbcClusterDTO jdbcClusterDTO) {
        log.debug("Request to save JdbcCluster : {}", jdbcClusterDTO);
        JdbcCluster jdbcCluster = jdbcClusterMapper.toEntity(jdbcClusterDTO);
        jdbcCluster = jdbcClusterRepository.save(jdbcCluster);
        return jdbcClusterMapper.toDto(jdbcCluster);
    }

    /**
     * Get all the jdbcClusters.
     *
     * @param pageable the pagination information.
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public Page<JdbcClusterDTO> findAll(Pageable pageable) {
        log.debug("Request to get all JdbcClusters");
        return jdbcClusterRepository.findAll(pageable)
            .map(jdbcClusterMapper::toDto);
    }


    /**
     * Get one jdbcCluster by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<JdbcClusterDTO> findOne(Long id) {
        log.debug("Request to get JdbcCluster : {}", id);
        return jdbcClusterRepository.findById(id)
            .map(jdbcClusterMapper::toDto);
    }

    /**
     * Delete the jdbcCluster by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete JdbcCluster : {}", id);
        jdbcClusterRepository.deleteById(id);
    }
}
